
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="format-detection" content="telephone=no">
    <meta name="viewport" content="minimal-ui,width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <title>订单详情-{$webseting.web_title}</title>
    <link href="__PUBLIC__/wap/css/rest.css"  rel="stylesheet">
    <link href="__PUBLIC__/wap/css/user.css"  rel="stylesheet">
    <link href="__PUBLIC__/wap/css/detailedTracking.css"  rel="stylesheet">
</head>
<body id="body">
<header id="header" class="u-header clearfix">
    <div class="u-hd-left f-left">
        <a href="{:U('wap/goodsorder/index')}" class="J_backToPrev"><span class="u-icon-px i-hd-back"></span></a>
    </div>
    <div class="u-hd-tit"><span>订单详情</span></div>
</header>
<div class="fwrap">
    <section class="order-con">
        <ul class="order-list">
            <li>
                <div class="order-box">
                    <div class="order-width">
                        <p>订单编号：{$data.order_sn}</p>
                        <p>订单金额：￥{$data.pay_price}</p>
                        <p>订单日期：{$data.upgrade_time}</p>
                        <p>支付状态：{$pay_status[$data['pay_status']]}
                        </p>
                    </div>
                </div>
            </li>
            <li>
                <div class="order-box">
                    <div class="order-width">
                        <p class="border-bottom usr-name">
                            推荐人:
                            <span class="fl">{$MemberDetail.recommend_name}</span>
                        </p>
                        <p class="border-bottom usr-name">
                            开&nbsp;店&nbsp;人&nbsp;:  <!-- 开店人姓名 -->
                            <!-- 收货人电话 -->
                            <span class="fl">{$data.member_name}</span>
                        </p>
                        <!-- 开店类型 -->
                        <p class="usr-addr">开店等级:
                            <span class="fl">{$data.levelName}</span>
                        </p>

                    </div>
                </div>
            </li>
            <if condition="$data['pay_status'] eq 0">

                <form action="" role="form" id="form2" novalidate="novalidate" method="post" onSubmit="return false;">
                    <li>
                        <div class="order-box">
                            <div class="order-width">
                                <p class="border-bottom usr-name">付款方式:<span class="fr"></span></p>
                                <div class="ui-form ui-border-b" style="margin-bottom: 0;border-bottom: none; ">
                                    <div class="ui-form ui-border-b" style="text-align: left;line-height: 40px;">
                                        <input id="pay_online"  class="pay_type" name="pay_type" type="radio" value="pay_online" checked="checked" style=" margin-left: 10px;">
                                        <label for="pay_online">在线支付</label>
                                        <span class="fr" style="margin-right:10px;">￥{$data['pay_price']}</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </li>

                    <if condition="$balance egt 1">
                        <li class="use_balance_pay">
                            <div class="ui-form ui-border-b">
                                <div class="ui-form ui-border-b" style="text-align: left;line-height: 40px;">
                                    <input id="use_balance" name="use_balance" type="checkbox" value="1" checked="checked" style=" margin-left: 10px;">
                                    <label for="use_balance">使用余额支付</label>
                                    <span class="fr" style="margin-right:10px;">可用余额：￥{$balance}</span>
                                </div>

                                <div class="ui-form-item ui-border-b input_password">
                                    <label style="width: 85px;">输入登录密码</label>
                                    <input style="padding: 12px 0 0 91px;" name="mem_password" id="mem_password" type="password" value="" placeholder="输入登录密码">
                                </div>
                            </div>
                        </li>
                        <else/>
                        <input name="use_balance" type="checkbox" value="1"   style=" display:none">
                    </if>
                    <input name="order_id" id="order_id" type="hidden" value="{$data.id}" placeholder="">
                    <li>
                        <div class="order-box">
                            <div class="order-width">
                                <a href="javascript:void(0);" id="go_pay" data="{$data.id}"   data-tpa="GOTO_CHECKOUT" class="new-abtn-type new-mg-tb30 phone_log_btn">
                                    去付款
                                </a>
                            </div>
                        </div>
                    </li>
                </form>
<!--                <elseif condition="$data['order_state'] eq 'delivered' && $ref_all eq 0"/>
                <li class="delivered_html">
                    <div class="order-box">
                        <span  style="color:red;">*确认收货后订单不可退换！</span>
                        <div class="order-width">
                            <a href="javascript:void(0);" data="{$data.order_id}" data-tpa="GOTO_CHECKOUT" class="new-abtn-type new-mg-tb30 delivered">
                                确认收货
                            </a>
                        </div>
                    </div>
                </li>-->
            </if>
        </ul>
    </section>
</div>

<div class="payFs m-t-15  pay_online_goo" style="display: none;">

    <div class="order-width">
        <a href="javascript:get_alipay_pay();" style="margin: 20px 0;" id="zfb" class="new-abtn-type pay_online_type onPay" data="alipay">支付宝</a>
    </div>

    <if condition="$is_weixin eq 1">
        <div class="order-width">
            <a href="javascript:get_weixin_pay();" id="wx"  style="background-color: #04A403;" class="new-abtn-type pay_online_type " data="wxpay">微信支付</a>
        </div>
    </if>
</div>

<include file="Public/wap_javascript" />


<script>
    //验证密码
    jQuery(document).ready(function() {
        //FormValidator.init();
        jQuery.validator.addMethod("passwordRequired", function(value) {
            var use_balance=$('input[name="use_balance"]').prop('checked');
            var ret=true;
            if(use_balance){
                if(!value){
                    ret=false;
                }
            }
            return ret;
        });

        $("#form2").validate({
            rules: {
                mem_password: {
                    passwordRequired: true,
                    rangelength: [6, 20]
                }
            },
            messages: {
                mem_password:{
                    passwordRequired:'<span class="icon-warning icon_warning"></span>&nbsp;请输入密码',
                    rangelength:'<span class="icon-warning icon_warning"></span>&nbsp;密码请保持6-20位'
                }
            },
            focusInvalid:false,
            success: function(label) {
            },
            submitHandler: function(editform) {

                var options = {
                    url :  "<?php echo U('Wap/start/start_pay_go'); ?>",
                    type : "post" ,
                    dataType:'json',
                    target : "#loader",
                    error: function(){layer.msg("服务器没有返回数据，可能服务器忙，请重试",{icon:5});},
                    onwait : "正在处理信息，请稍候...",
                    success: function(response){
                        // console.log(response);
                        //$("#loader").fadeIn(500).html(response.data).fadeOut(500); 
                        //$('#editform').hide(2000); 
                        if(response.status==1){
                            //layer.msg('支付成功',{icon:6});
                            if(response.need_pay==1){
                                /*  window.location.href="<?php  echo U('Wap/Mallpayment/index',array('pay_sn'=>$data['order_sn']));?>";*/
                                if(response.pay_url!='' && typeof(response.pay_url)!=undefined){
                                    // window.location.href=response.pay_url;
                                    //go_weixin_pay();
                                    get_weixin_pay(response.pay_url);
                                }else{
                                    layer.msg('系统错误请稍候再试', {icon: 5});
                                }
                                //layer.msg('修改成功，请重新登录',{icon:6});
                            }else{
                                layer.msg('支付成功',{icon:6,time: 1500},function(){
                                   /* window.location.href="<?php  echo U('wap/goodsorder/order_detail',array('id'=>$data['order_id']));?>";*/
                                    window.location.href="<?php  echo U('wap/start/gift_address',array('order_id'=>$data['order_id'],'order_sn'=>$data['id']));?>";
                                });
                            }

                            /* layer.msg("修改成功，请重新登录。",{icon:6},function(){
                             window.location.href="<?php echo U('Wap/Login/loginout'); ?>";
                             });*/
                        }else{
                            layer.msg(response.error,{icon:5});
                        }
                    }
                };
                setTimeout((function(opt){
                    return function(){
                        layer.msg("正在处理信息，请稍候...",{time:100000});
                        $('#form2').ajaxSubmit(opt);
                    }
                })(options), 300);
                return false;
            }

        });
        $('#go_pay').click(function(){
            var use_balance=$('input[name="use_balance"]').prop('checked');
            var pay_type=$('input[name="pay_type"]:checked').val();
			$('#form2').submit();
        });
    });

</script>
<script type="text/javascript">
    $(function(){
        $('#use_balance').click(function(){
            set_use_balan();
        });
        set_use_balan();
        $('input[name="pay_type"]').change(function(){
            set_pay_type();
        });
        set_pay_type();
    });
    function set_use_balan(){
        var use_balance=$('#use_balance').prop('checked');
        if(use_balance){
            $(".input_password").show();
        }else{
            $(".input_password").hide();
        }
    }
    function set_pay_type(){
        var pay_type=$('input[name="pay_type"]:checked').val();
        if(pay_type=='pay_online'){
            $(".use_balance_pay").show();
            $('#use_balance').prop('checked',true);
            set_use_balan()
        }else{
            var need_pay=$('input[name="pay_type"]:checked').attr('data-pay');
            if(need_pay==1){
            }else{
                $(".use_balance_pay").hide();
                $('#use_balance').prop('checked',false);
                set_use_balan()
            }
        }
    }
</script>
<style>
    .layui-layer-setwin .layui-layer-close2{
        /* right: 0px; */
        top: -10px;
    }
</style>
<script type="text/javascript">
    function get_weixin_pay(url){
        ///需要支付
        var pay_url="<?php echo 'http://'.$_SERVER['HTTP_HOST'].'/api/payment/wpay/jsapi_go_pay.php?pay_sn='.$data['order_sn'].'&levelId='.$data['levelId'].'&order_id='.$data['order_id']; ?>";
        window.location.href=pay_url+"&openid=<?php echo $_SESSION['user_open_id'];?>";
        return false;
    }

    function go_pay_online(){
        layer.closeAll(); //疯狂模式，关闭所有层
        layer.open({
            type: 1,
            shade: 0.8,//透明度
            title: false, //不显示标题
            skin: 'layui-layer-demo', //样式类名
            shadeClose: true, //开启遮罩关闭
            closeBtn: 0, //不显示关闭按钮
            area: ['80%', 'auto'],
            scrollbar: false,//浏览器滚动锁定
            content: $('.pay_online_goo'), //捕获的元素
            cancel: function(index){

                layer.close(index);
                this.content.show();
                $('.pay_online_goo').hide();
                //layer.msg('捕获就是从页面已经存在的元素上，包裹layer的结构',{time: 5000});
            }
        });
    }
    function get_alipay_pay(){
        var order_sn="<?php echo $data['order_sn']; ?>";
        $.ajax({
            url:  "<?php echo U('wap/goodsorder/go_alipay_pay'); ?>",
            type: 'get',
            data: {order_sn:order_sn},
            dataType: 'json',
            success: function (data) {
                if (data.status == 1) {
                    var pay_url = "<?php echo U('wap/Alipay/index') ?>";
                    window.location.href = pay_url + '?pay_sn=' + order_sn;
                } else {
                    layer.msg(data.error, {icon: 5});
                    //alert(data.error)
                }
            }
        });
    }

    function go_weixin_pay(){
        layer.msg('连接FG峰购收银台....',{time: 100000});
        $.ajax({
            //  url: "{:U('wap/goodsorder/get_pay_url')}",
            url:"<?php echo U('wap/goodsorder/go_wx_pay'); ?>",
            type:'get',
            data: {pay_sn:"<?php echo $data['id']; ?>",pay:'1'},
            dataType: 'json',
            success: function(data){
                if(data.status==1){
                    if(data.pay_url!='' && typeof(data.pay_url)!=undefined){
                        get_weixin_pay(data.pay_url);
                    }else{
                        layer.msg('系统错误请稍候再试', {icon: 5});
                    }
                }else{
                    layer.msg(data.error, {icon: 5});
                }
            }
        });
    }
</script>
</body>
</html>